package thread;

public class Demo4 {
//线程中断方法1=---使用自定义的变量来作为标志位
    private static boolean isQuit=false;

    public static void main(String[] args) throws InterruptedException {
        Thread t=new Thread(()->{
            while (!isQuit) {
                try {
                    System.out.println("转账中");
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("转账终止");
        });
        System.out.println("开始转账");
        t.start();
        Thread.sleep(1000*10);
        System.out.println("突然有人说停止转账");
        isQuit=true;

    }


}
